<template>
    <div v-show="showDialog">
        <transition name="fade" appear>
            <div class="modal-overlay"></div>
        </transition>
        <audio ref="audioPlayer">
            <source src="../assets/imgs/hh.mp3" />
        </audio>
        <div class="modal animate__animated animate__bounce" role="dialog" :style="{ width: `60%` }">
            <div class="model-title">
                <img src="../assets/imgs/bg-one.png" alt="">
                <div class="money">￥{{ money.zje }}</div>
            </div>
        </div>
    </div>
</template>



<script setup>
import { toRefs, onMounted, ref, watch, nextTick, onBeforeMount } from 'vue'

const props = defineProps({
    showDialog: Boolean,
    money: Object
    
})

const emit = defineEmits(['change']);

const { showDialog } = toRefs(props)

const audioPlayer = ref(null);//播放器dom元素

// 监听
watch(showDialog, (newVal, oldVal) => {
    if (newVal) {
        console.log(showDialog,'!!!!1213131');
        audioPlayer.value.play();
        setTimeout(() => {
            changeModel()
            audioPlayer.value.pause()
        }, 5000)
    }
})


onMounted(() => {
    // if (audioPlayer.value !== null) {
    // console.log(showDialog,'!!!!');
    // if(showDialog){
    //     console.log(showDialog,'!!!!1213131');
        
    // }
    // }
})

const changeModel = () => {
    emit('change', false);
}
// }
</script>
<style scoped lang="scss">
.modal {
    // position: absolute;
    position: fixed;
    top: 0rem;
    right: 0;
    bottom: 0;
    left: 0;
    margin: auto;
    // height: fit-content;
    min-width: 400px;
    border-radius: 16px;
    overflow: hidden;
    z-index: 999;
    border-radius: 4px;
    transform: none;
}

.model-title {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    height: 100%;
    text-align: center;
    overflow: hidden;
    width: 100%;
    color: #fff;

    .money {
        // font-size: 128px;
        font-size:calc(100vw * 128 / 1920); 
        font-weight: bold;
        position: absolute;
        top: 35%;
        left: 20%;
    }

    img {
        position: absolute;
        top: 0%;
        width: 90%;
        height: 70%;
    }
}

.modal-overlay {
    content: '';
    position: absolute;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 998;
    background: #000;
    opacity: .7;
}
</style>